// 存储模块

// getItem
export const getItem = name => {
  const result = localStorage.getItem(name)
  try {
    // 如果JSON.parse转换成功，就证明是json字符串转换成功了，返回，如果失败了，就返回原数据
    return JSON.parse(result)
  } catch (error) {
    return result
  }
}

// setItem
export const setItem = (name, data) => {
  if (typeof data === 'object') {
    data = JSON.stringify(data)
  }
  localStorage.setItem(name, data)
}

// removeItem
export const removeItem = name => {
  localStorage.removeItem(name)
}
